package lib.android.clean.reflection

/**
 * <br>createBy Gw
 * <br>createTime: 2021/7/15 15:19
 */

val String.clazz get() = Class.forName(this)

fun Class<*>.field(name:String, target: Any): Any?{
    val field = getDeclaredField(name)
    val accessible = field.isAccessible
    field.isAccessible = true
    val value = field.get(target)
    field.isAccessible = accessible
    return value
}

fun Any.field(name:String, ownerClass: Class<*>): Any?{
    val field = ownerClass.getDeclaredField(name)
    val accessible = field.isAccessible
    field.isAccessible = true
    val value = field.get(this)
    field.isAccessible = accessible
    return value
}